package com.ny.Dao.impl;

import com.ny.entity.Order;
import com.ny.until.SqlConnection;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    private SqlConnection sqlConnection = new SqlConnection();
    public OrderDaoImpl () throws SQLException, ClassNotFoundException ,  SQLException{
        sqlConnection.getConnection();
    }

    @Override
    public int addOrder(Order order) throws SQLException, ClassNotFoundException {
        String sql = "insert into orders(student_id,product_id,number,total_price)values(?,?,?,?)";
        PreparedStatement preparedStatement = sqlConnection.getConnection().prepareStatement(sql);
        preparedStatement.setInt(1,order.getStudent_Id());
        preparedStatement.setInt(2,order.getProduct_Id());
        preparedStatement.setInt(3,order.getNumber());
        preparedStatement.setInt(4,order.getTotal_Price());

        return  preparedStatement.executeUpdate();


    }
}
